import * as ActionTypes from '../../action/types';
import { EGender, TUserInfo } from '../../../types';

const initUserInfo: TUserInfo = {
  avatarUrl: '',
  gender: EGender.Male,
  nickName: '',
  signUpDate: new Date(),
  permission: false,
  openId: '',
  userLink: ''
};

export const userInfoReaducer = (state: TUserInfo = initUserInfo, action: any) => {
  const { type, payload } = action;
  switch (type) {
    case ActionTypes.SET_USERINFO:
      return { ...state, ...payload };
    case ActionTypes.SET_USERINFO_PERMISSION:
      return { ...state, permission: payload };
    case ActionTypes.SET_USERLINK:
      return { ...state, userLink: payload };
    default:
      return state;
  }
};
export default userInfoReaducer;
